{% extends 'base.html' %}

{% load static %}

{% block css %}
    <link rel="stylesheet" href="{% static 'css/homeworkapp/homewrok.css' %}">
{% endblock %}

{% block js %}
    <script type="text/javascript">
        window.onload = function check() {
            $.ajax({
                url: "/homework/check/",
                type: "get",
                data: {
                    "h": $("input[name='h']").val(),
                },
                success: function (data) {
                    if (data["status"] === true) {
                        $(".homework-submit").attr('disabled', 'disabled');
                        {# 作业已提交，禁止再次提交 #}
                        $(".homework-submit-tip").removeAttr('hidden');
                        {# 作业已提交提示 #}
                    } else if (data["status"] === false) {
                        $(".homework-submit").removeAttr('disabled');
                        $(".homework-submit-tip").attr('hidden', 'hidden')
                    }
                }
            });
        };
    </script>
{% endblock %}

{% block content %}
    <div class="container">
        <div class="row">
            <div class="question">
                <form id="{{ question.id }}" method="post" action="{% url 'homework:judge' %}">
                    {% csrf_token %}
                    <input hidden name="h" value="{{ h_id }}"> {# 作业id #}
                    <ul>
                        <h5>一、判断题</h5>
                        {% for question in pd_list %}
                            <li>
                                <h5>{{ forloop.counter }}.&nbsp;{{ question.context }}</h5>
                                <input type="hidden" value="{{ question.id }}"/>
                                <input name="{{ question.id }}" type="radio" value="true"/>&nbsp;正确
                                <br/>
                                <input name="{{ question.id }}" type="radio" value="false"/>&nbsp;错误
                                <br/>
                            </li>
                        {% endfor %}
                    </ul>
                    <br/>
                    <ul>
                        <h5>二、选择题</h5>
                        {% for question in xz_list %}
                            <li>
                                <h5>{{ forloop.counter }}.&nbsp;{{ question.context }}</h5>
                                <input type="hidden" value="{{ question.id }}"/>
                                <input name="{{ question.id }}" type="radio" value="A"/>&nbsp;A.{{ question.choice_a }}
                                <br/>
                                <input name="{{ question.id }}" type="radio" value="B"/>&nbsp;B.{{ question.choice_b }}
                                <br/>
                                <input name="{{ question.id }}" type="radio" value="C"/>&nbsp;C.{{ question.choice_c }}
                                <br/>
                                <input name="{{ question.id }}" type="radio" value="D"/>&nbsp;D.{{ question.choice_d }}
                                <br/>
                            </li>
                        {% endfor %}
                    </ul>
                    <br/>
                    <ul>
                        <h5>三、简答题</h5>
                        {% for question in jd_list %}
                            <li>
                                <h5>{{ forloop.counter }}.&nbsp;{{ question.context }}</h5>
                                <input type="hidden" value="{{ question.id }}"/>
                                <textarea name="{{ question.id }}" placeholder="在此作答" class="form-control"></textarea>
                                <br/>
                            </li>
                        {% endfor %}
                    </ul>
                    <input type="submit" class="btn btn-primary homework-submit" value="确认提交">&nbsp;
                    <span class="homework-submit-tip" hidden="hidden" style="color: red">你已作答</span>
                </form>
            </div>
        </div>
    </div>
{% endblock %}